define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order/index/trade_type/'+ trade_type + location.search,
                    // add_url: 'user/user/add',
                    // edit_url: 'user/user/edit',
                    // del_url: 'user/user/del',
                    multi_url: 'order/order/multi',
                    import_url: 'order/order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'channelCode', title: __('ChannelCode')},
                        {field: 'admin.nickname', title: '商户', searchable: false},
                        {field: 'outTradeNo', title: __('Outtradeno'), operate: 'LIKE'},
                        {field: 'memberName', title: __('Membername'), operate: 'LIKE'},
                        {field: 'certNo', title: __('Certno'), operate: 'LIKE'},
                        {field: 'cardNo', title: __('Cardno'), operate: 'LIKE'},
                        {field: 'phoneNo', title: __('Phoneno'), operate: 'LIKE'},
                        {field: 'txnAmount', title: __('TxnAmount'),searchable:false},
                        {field: 'charge', title: __('Charge'),searchable:false},
                        {field: 'notifyUrl', title: __('NotifyUrl'),searchable:false},
                        {field: 'shouyi', title: __('Shouyi'),searchable:false},
                        {field: 'status', title: '订单状态',visible: false,searchList: {0: "处理中",1: "成功", '-1': "失败"}},
                        {field: 'tradeNo', title: __('TradeNo')},
                        {field: 'store_id', title: '商户', visible: false,addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'",searchable:table.attr('data-super-admin') == 1},
                        {field: 'description', title: __('Description'),searchable:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,defaultValue: table.attr('data-default-createtime')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [
                                {
                                    name: '重发回调',
                                    title: __('重发回调'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-refresh',
                                    confirm: '确认重发回调？',
                                    url: 'order/order/huidiao/trade_type/'+ trade_type,
                                    success: function (data, ret) {
                                    },
                                    error: function (data, ret) {
                                    }
                                },
                                {
                                    name: 'reappear',
                                    text: '重出',
                                    title: '重出',
                                    classname: 'btn btn-info btn-xs btn-ajax', //按钮的class，支持btn-dialog/btn-ajax/btn-addtabs
                                    icon: 'fa fa-refresh', //按钮的图标
                                    url: 'order/order/reappear/id/{ids}',
                                    confirm: function(row){
                                        return '是否重出('+row.outTradeNo+')?';
                                    },
                                    refresh: true,
                                    disable: function(row){
                                        return table.attr('data-operate-reappear') != 1 || row.tradeType != 2;
                                    },
                                    visible: function(row){
                                        return table.attr('data-operate-reappear') == 1 && row.tradeType == 2;
                                    }, 
                                },
                            ],formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});